package org.zk.dubbo_consumer.util;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.zk.entity.User;

public class RequestUtils {
    private static Logger logger = LoggerFactory.getLogger(RequestUtils.class);

    /**
     * 获取当前登录的用户，若用户未登录，则返回未登录 json
     *
     * @return
     */
    public static User currentLoginUser() {
        Subject subject = SecurityUtils.getSubject();
        if (subject.isAuthenticated()) {//判断用户是否登录，如果登录则进入，返回值为boolean类型
            Object principal = subject.getPrincipals().getPrimaryPrincipal();
            if (principal instanceof User) {
                return (User) principal;//如果登录，则返回用户的json
            }
        }
        return null;//如果未登录，则返回null
    }
}
